package ms.jacrim.tropos;

import org.w3c.dom.Element;

public class Dependency extends Relationship {

	public enum DependencyType {
		DELEGATION_EXECUTION, DELEGATION_PERMISSION, DISTRUST_EXECUTION, DISTRUST_PERMISSION, MONITORING_EXECUTION, MONITORING_PERMISSION, TRUST_EXECUTION, TRUST_MONITOR, TRUST_PERMISSION
	};

	private static final String DEPENDENCY_TEMPLATE = "<object xmi:type=\"%s\" xmi:id=\"%s\""
			+ " source=\"%s\" target=\"%s\" dependencyType=\"%s\" />\r\n";

	private DependencyType dependencyType;

	public Dependency(Diagram diagram, TroposObject source, TroposObject target) {
		super(diagram, source, target);
		setType(TroposObject.DEPENDENCY);
	}

	public Dependency(Diagram diagram, Element element) {
		super(diagram, element);
	}

	void populate(Element element) {
		super.populate(element);

		this.dependencyType = DependencyType.valueOf(element.getAttribute("dependencyType"));
	}

	public DependencyType getDependencyType() {
		return dependencyType;
	}

	public void setDependencyType(DependencyType dependencyType) {
		this.dependencyType = dependencyType;
	}

	void toString(StringBuilder result, int part, int indent) {
		super.toString(result, part, indent);
		if (part == 0) {
			writeIndent(result, indent);
			result.append(String.format(DEPENDENCY_TEMPLATE, this.getType(), this.getId(), this.getSourceId(), this.getTargetId(),
					this.dependencyType));
		}
	}

	@Override
	protected int NotationEdgeType() {
		return 3004;
	}
}
